from tjob.initialize.setup_envs import (
    _DLC_PARAMS,
)

from tjob.utils.parse_file import parse_dlc_params


def test_py_file(file):
    # os.system(
    #     f"tjob submit {file}"
    # )
    namespace = {}
    exec(open(file).read(), namespace)
    print(_DLC_PARAMS)
    dlc_yaml = parse_dlc_params(_DLC_PARAMS)
    cpu1 = dlc_yaml["worker_cpu"]
    cpu2 = namespace["num_cpu"]

    gpu1 = dlc_yaml["worker_gpu"]
    gpu2 = namespace["num_gpu"]
    assert str(cpu1) == str(cpu2), f"{cpu1} != {cpu2}"
    assert str(gpu1) == str(gpu2), f"{gpu1} != {gpu2}"


if __name__ == "__main__":
    file = "tests/cmd/submit/test_py1.py"
    test_py_file(file)
